package com.mystnihon.freeremote.loader.torrent;

import android.util.Log;
import ca.benow.transmission.TransmissionClient;
import ca.benow.transmission.model.TorrentStatus;
import ca.benow.transmission.model.TorrentStatus.TorrentField;

import com.mystnihon.freeremote.config.Config;
import com.mystnihon.freeremote.data.ListOfTorrentStatus;
import com.octo.android.robospice.request.SpiceRequest;

public class GetTorrentsRequest extends SpiceRequest<ListOfTorrentStatus> {
	private static final String TAG = GetTorrentsRequest.class.getSimpleName();
	TransmissionClient mclient;
	int ids[] = null;
	TorrentStatus.TorrentField[] requestedFields = new TorrentField[] { TorrentField.id, TorrentField.name,
			TorrentField.status, TorrentField.percentDone, TorrentField.addedDate, TorrentField.startDate,
			TorrentField.doneDate, TorrentField.files, TorrentField.uploadRatio, TorrentField.peers,
			TorrentField.uploadedEver, TorrentField.downloadedEver,TorrentField.downloadDir, TorrentField.totalSize, TorrentField.sizeWhenDone,TorrentField.eta };

	public GetTorrentsRequest(TransmissionClient client) {
	    super(ListOfTorrentStatus.class);
	    mclient = client;
	}
	
	public void cancel(){
	    mclient.cancel();
	}

	public GetTorrentsRequest(TransmissionClient client, TorrentStatus.TorrentField[] requestFields, int id) {
	    super(ListOfTorrentStatus.class);
		mclient = client;
		requestedFields = requestFields;
		ids = new int[] { id };
	}

    @Override
    public ListOfTorrentStatus loadDataFromNetwork() throws Exception {
        if (Config.DEBUG_MODE_ENABLED)
            Log.d(TAG, "Loading");
        return new ListOfTorrentStatus(mclient.getTorrents(ids, requestedFields));
    }

}
